package com.iss.ljx.organ.controller;

import com.iss.ljx.mybatis.entity.PtDutyEntity;
import com.iss.ljx.mybatis.entity.PtMenuEntity;
import com.iss.ljx.mybatis.entity.PtOrganEntity;
import com.iss.ljx.mybatis.flexigrid.PadingRstType;
import com.iss.ljx.mybatis.flexigrid.PagingBean;
import com.iss.ljx.mybatis.ztree.ZtreeEntity;
import com.iss.ljx.organ.entity.SearchOrganEntity;
import com.iss.ljx.organ.service.OrganService;
import com.iss.ljx.spring.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.security.access.annotation.Secured;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName OrganController
 * @Description TODO
 * @Author 早起之王
 * @Date 2022/5/17 16:50
 **/
@Controller
@Slf4j
@RequestMapping("/organ")
public class OrganController extends BaseController {
    private Logger logger = LogManager.getLogger(this.getClass());
    @Resource
    private OrganService organService;

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/organPage")
    public String rolePage(){
        return "organ/organPage";
    }

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/queryOrganListPage")
    @ResponseBody
    public PadingRstType<PtOrganEntity> queryOrganListPage(SearchOrganEntity search, PagingBean paging){
        logger.info(search);
        logger.info(paging);
        PadingRstType<PtOrganEntity> ptOrganEntityPadingRstType = organService.queryOrganListPage(search,paging);
        return ptOrganEntityPadingRstType;
    }


    @RequestMapping("/organAdd")
    @ResponseBody
    public String add(PtOrganEntity ptOrganEntity){
        organService.insertOrgan(ptOrganEntity);
        return getSuccessMsg("organ.add.success");
    }
    @RequestMapping("/organDelete")
    @ResponseBody
    public String roleDelete(String organUuid){
        organService.organDelete(organUuid);
        return getSuccessMsg("organ.delete.success");
    }
    @RequestMapping("/organUpdate")
    @ResponseBody
    public String roleUpdate(PtOrganEntity ptOrganEntity){
        organService.organUpdate(ptOrganEntity);
        return getSuccessMsg("organ.update.success");
    }

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/getOrganTreeByOrganUuid")
    @ResponseBody
    public List<ZtreeEntity> getOrganTreeByOrganUuid(@RequestParam("organUuid") String organUuid){
        logger.info("organUuid:" +  organUuid);
        return organService.getOrganTreeByOrganUuid(organUuid);
    }

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/boundOrgan")
    @ResponseBody
    public String boundOrgan(@RequestParam("organUuid") String organUuid,@RequestParam("parentUuid") String parentUuid){
        logger.info("OrganUuid:" +  organUuid + " parentUuid:" + parentUuid);
        organService.boundOrgan(organUuid,parentUuid);
        return getSuccessMsg("organ.bound.success");
    }

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/getOrganInfoByUuid")
    @ResponseBody
    public PtOrganEntity getOrganInfoByUuid(@RequestParam("organUuid") String organUuid){
        logger.info("organUuid:" + organUuid);
        return organService.getOrganInfoByUuid(organUuid);
    }

    @Secured("ROLE_gqgy_data_role")
    @RequestMapping("/unBoundByOrganUuid")
    @ResponseBody
    public String unBoundByOrganUuid(@RequestParam("organUuid") String organUuid){
        logger.info("organUuid:" +  organUuid);
        organService.unBoundByOrganUuid(organUuid);
        return getSuccessMsg("organ.unbound.success");
    }


}

